package com.qf.agro.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.agro.common.ResultInfo;
import com.qf.agro.mapper.DeviceTypeMapper;
import com.qf.agro.mapper.SmartDeviceTypeMapper;
import com.qf.agro.pojo.SmartDeviceType;
import com.qf.agro.service.DeviceTypeService;
import com.qf.agro.vo.OptionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 10202
 * @version V1.0
 * @Project smart-agriculture-parent
 * @Package com.qf.agro.service.impl
 * @Date 2023/7/4 14:13
 */
@Service
public class DeviceTypeServiceImpl implements DeviceTypeService {
    @Autowired
    private DeviceTypeMapper deviceTypeMapper;
    @Autowired
    private SmartDeviceTypeMapper smartDeviceTypeMapper;

    @Override
    public ResultInfo devicePage(Long page, Long pageSize, String name) {
        Page<SmartDeviceType> smartDevicePage =new Page<>(page,pageSize);
        LambdaQueryWrapper<SmartDeviceType> lqw=new LambdaQueryWrapper<>();
        lqw.eq(name!=null,SmartDeviceType::getTypeName,name);
        Page<SmartDeviceType> smartDeviceTypePage = deviceTypeMapper.selectPage(smartDevicePage, lqw);
        return ResultInfo.success(smartDeviceTypePage);
    }

    @Override
    public ResultInfo getOptions() {

        List<OptionVo> optionVos = smartDeviceTypeMapper.selectOptions();

        return ResultInfo.success(optionVos);
    }
}
